﻿#include <iostream>

#include <breaking/thread/thread.h>

#include <fmt/format.h>
#include <breaking/time/time_utility.h>
#include <breaking/time/timer.h>
#include <breaking/time/time.h>
#include <breaking/time/date.h>
#include <breaking/base/singleton.h>

#include <breaking/log/logger.h>
#include <breaking/log/file_log_appender.h>
#include <breaking/log/console_log_appender.h>

#include <chrono>
#include <iomanip> // 用于设置输出格式

#ifdef BREAKING_OS_WINDOWS
#define INFO_LOG_FORMAT(format_str, ...) breaking::logger::instance().log_format(breaking::log_priority::LOG_INFO, __FILE__, __FUNCTION__, __LINE__, format_str, ##__VA_ARGS__)
#else
#define INFO_LOG_FORMAT(format_str, args...) breaking::logger::instance().log_format(breaking::log_priority::LOG_INFO, __FILE__, __FUNCTION__, __LINE__, format_str, ##args)
#endif //

int num = 1;
std::mutex pm;
class test_thread : public breaking::thread
{
public:
	virtual void run() override
	{
		while (!is_stop_requested())
		{
			pm.lock();
			num++;
			//std::string logstr = fmt::format("test({}) kkk({})", 4567, "opop111");
			std::cout << "-----------------------------------------" << get_id() << std::endl;
			std::cout << "time:[" << breaking::time_utility::GetCurrentMSec() << "]" << "xx" << std::endl;
			// 使用系统时钟获取当前时间点
			auto now = std::chrono::system_clock::now();
			// 转换为自纪元以来的毫秒数
			std::cout << "time:[" << std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() << "]" << "xx" << std::endl;
			std::cout << "time:[" << breaking::time_utility::GetCurrentUSec() << "]" << "num : " << num << std::endl;
			now = std::chrono::system_clock::now();
			std::cout << "time:[" << std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() << "]" << "num : " << num << std::endl;
			std::cout << "-----------------------------------------" << std::endl;

			INFO_LOG_FORMAT("test({}) kkk({})", 4567, "rqrqr");

			pm.unlock();

			breaking::thread::sleep(1000);
		}
	}
};

int main()
{
	std::cout << "test test ..." << std::endl;

	breaking::logger::instance().add_appender(new breaking::file_log_appender("./logs/test"));
	breaking::logger::instance().add_appender(new breaking::console_log_appender());

	//breaking::time tt = 1722778489898;

	//// 输出时间，单位为秒
	//std::cout << "time: " << tt.sec() << " s" << std::endl;
	//// 输出时间，单位为毫秒
	//std::cout << "time: " << tt.msec() << " ms" << std::endl;

	//// 将时间转换为日期
	//breaking::date dd(tt);
	//// 输出日期，单位为年
	//std::cout << "date: " << dd.year() << std::endl;
	//// 输出日期，单位为月
	//std::cout << "date: " << dd.month() << std::endl;
	//// 输出日期，单位为日
	//std::cout << "date: " << dd.day() << std::endl;
	//// 输出日期，单位为时
	//std::cout << "date: " << dd.hour() << std::endl;
	//// 输出日期，单位为分
	//std::cout << "date: " << dd.minute() << std::endl;
	//// 输出日期，单位为秒
	//std::cout << "date: " << dd.sec() << std::endl;
	//// 输出日期，单位为毫秒
	//std::cout << "date: " << dd.msec() << std::endl;
	//// 输出日期，单位为周
	//std::cout << "date: " << dd.week() << std::endl;
	//// 输出日期，单位为月
	//std::cout << "date: " << dd.get_days_in_month() << std::endl;
	//// 输出日期，单位为字符串
	//std::cout << "date: " << dd.to_string() << std::endl;

	//// 输出当前日期
	//breaking::date nn(breaking::time::current_time());
	//std::cout << "current date: " << nn.to_string() << std::endl;

	//return 0;

	test_thread t1;
	test_thread t2;

	t1.activate();
	t2.activate();

	breaking::thread::sleep(5000);

	t1.stop();
	t2.stop();

	return 0;
}